<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/common.min.css">
    <link rel="stylesheet" href="../css/login_register.min.css">
</head>

<body>
    <header>
        <img src="../images/1.png" alt="">

    </header>
    <main>
        <div class="head">
            用户注册
        </div>

        <div class="two" id="inp1">
            <span>注册账号:</span> <input type="text" id="inp3">
        </div>
        <div class="two" id="inp2">
            <span>注册密码:</span> <input type="password" id="inp4">
        </div>

        <div class="but">
            <button id="btn">注册</button><a href="./login.html">已有账号，直接登录</a>
        </div>
    </main>

    <script src="./bootstrap/jquery-3.0.0/jquery-3.0.0.js"></script>
    <script>
        $("#btn").click(function () {
            let username = $("#inp3").val();
            let password = $("#inp4").val();
            $.ajax({
                url: '/users/register',
                type: "POST",
                data: {
                    username, password
                },
                success: function (res) {
                    console.log(res);

                    if (res.code) {
                        alert('注册成功')
                    }
                    else {
                        alert('用户名已存在，请重新输入')
                    }
                }

            })
        })
    </script>
</body>

</html>